#include "stdafx.h"

Label::Label(int left, int top)
{
	this->left = left;
	this->top = top;

	update_graphical();
}

Label::~Label()
{
	delete_graphical();
}

void Label::draw(Gdiplus::Graphics & graphics)
{
	Gdiplus::RectF temp;
	Gdiplus::PointF origin = { 0,0 };

	graphics.MeasureString(caption.c_str(), caption.length(), font, origin, &temp);
	origin.X = left;
	origin.Y = top - temp.Height / 2.0;
	graphics.DrawString(caption.c_str(), -1, font, origin, brush_text);
}

void Label::update_graphical()
{
	if (ffm)
	{
		delete ffm;
	}
	if (font)
	{
		delete font;
	}
	if (brush_text)
	{
		delete brush_text;
	}

	ffm = new Gdiplus::FontFamily(fontname.c_str());
	font = new Gdiplus::Font(ffm, fontsize);
	brush_text = new Gdiplus::SolidBrush(color_text);
}

void Label::delete_graphical()
{
	if (ffm)
	{
		delete ffm;
	}
	if (font)
	{
		delete font;
	}
	if (brush_text)
	{
		delete brush_text;
	}
}

void Label::set_color_text(Gdiplus::Color color)
{
	color_text = color;

	update_graphical();
}

void Label::set_fontname(std::wstring name)
{
	fontname = name;

	update_graphical();
}

void Label::set_fontsize(int size)
{
	fontsize = size;

	update_graphical();
}